package org.xteam.sled.tree;

public class TreePrinter {

	public void print(Tree t) {
		print(t, 0);
	}

	private void print(Tree t, int indent) {
		if (t instanceof TreeNode) {
			TreeNode node = (TreeNode) t;
			System.out.println(node.getField());
			for (Edge edge : node.getEdges()) {
				printIndent(indent+1);
				System.out.print(edge.getRange() + " => ");
				print(edge.getTree(), indent+2);
			}
		} else {
			LeafNode leaf = (LeafNode) t;
			System.out.println(leaf.getArms());
		}
	}

	private void printIndent(int indent) {
		while (indent-- > 0) {
			System.out.print(' ');
		}
	}

}
